<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    // obj: 目标对象
    // prop: 定义的属性或方法
    // descriptor: prop所具有的特性

    function defineReactive(obj, prop, descriptor) {
        Object.defineProperty(obj, prop, {
            enumerable: true,
            configurable: true,
            get: () => {
                console.log('我被读了,要不要做点什么好')
            },
            set: newVal => {
                if (descriptor === newVal) {
                    return
                }
                descriptor = newVal
                console.log('数据的值改变了')
            }
        })
    }

    let data = {text: 'hello world'};
    defineReactive(data, 'msg', 'this is a book');
    console.log(data)
</script>
</body>
</html>
